//
//  OCTempView.m
//  ocVB
//
//  Created by apple on 2016/10/24.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "OCTempView.h"


@interface OCTempView ()
/**
 详情label
 */
@property(nonatomic,weak)UILabel * detailLabel;

/**
 界面画面
 */
@property(nonatomic,weak)UIImageView * iconView;

/**
 根视图
 */
@property(nonatomic,weak)UIImageView * rootView;

@end


@implementation OCTempView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor colorWithWhite:236 / 255.0 alpha:1];
        [self setupUI];
    }
    return self;
}

/**
 按钮点击事件
 */
-(void)btnCLick{
    self.callBack();
}

#pragma mark -- 搭建界面
- (void)setupUI
{
    // 动画视图
    UIImageView *rootView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    [self addSubview:rootView];
    [rootView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    //遮罩视图
    UIImageView *keepView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    [self addSubview:keepView];
    [keepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    //主页视图
    UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    [self addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    //说明label
    UILabel *desstailLabel = [UILabel makeLabelText:@"你好啊,主页" andTextColor:[UIColor lightGrayColor] andTextFont:14];
    desstailLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:desstailLabel];
    [desstailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.offset(230);
        make.top.equalTo(rootView.mas_bottom).offset(10);
    }];
    ///登录按钮
    UIButton *loadBtn = [UIButton makeButtonWithImgName:nil backgroundImagName:@"common_button_white" title:@"登录" titleColor:ORANGECOLOR tagert:self selector:@selector(btnCLick)];
    [self addSubview:loadBtn];
    [loadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(desstailLabel.mas_bottom).offset(8);
        make.left.equalTo(desstailLabel);
        make.size.mas_equalTo(CGSizeMake(100, 35));
    }];
    ///注册按钮
    UIButton *registBtn = [UIButton makeButtonWithImgName:nil backgroundImagName:@"common_button_white" title:@"注册" titleColor:ORANGECOLOR tagert:self selector:@selector(btnCLick)];
    [self addSubview:registBtn];
    [registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(loadBtn);
        make.right.equalTo(desstailLabel);
        make.centerY.equalTo(loadBtn);
        
    }];
    self.rootView = rootView;
    self.detailLabel = desstailLabel;
    self.iconView = iconView;
}
- (void)setTitle:(NSString *)title imagName:(NSString *)imgName
{
   
    if (title != nil && imgName != nil) {
        self.detailLabel.text = title;
        self.iconView.image = [UIImage imageNamed:imgName];
         self.rootView.hidden = YES;
    }else{
        CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        ani.repeatCount = CGFLOAT_MAX;
        ani.duration = 20;
        [ani setToValue:@(M_PI * 2)];
        [ani setRemovedOnCompletion:NO];
        [self.rootView.layer addAnimation:ani forKey:nil];
    }
    
    
    
}

@end
